package com.spider.im.login.controller;


import com.spider.im.common.annotation.IgnoreLog;
import com.spider.im.common.annotation.RedisLock;
import com.spider.im.common.aspect.RespResult;
import com.spider.im.common.utils.EncryptionUtils;
import com.spider.im.login.req.LoginReq;
import com.spider.im.login.resp.LoginUser;
import com.spider.im.login.service.LoginHandlerContext;
import com.spider.im.login.service.LoginService;
import com.spider.im.sms.service.SmsService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "AuthController",  description = "登录管理")
@RequestMapping("/api/auth")
@RestController
public class AuthController {

    @Resource
    private LoginHandlerContext loginHandlerContext;
    @Resource
    private EncryptionUtils encryptionUtils;


    @IgnoreLog
    @Schema(description = "login 登录")
    @PostMapping("/login")
    public RespResult<LoginUser> login(@RequestBody LoginReq loginReq)  {

        LoginService loginService = loginHandlerContext.getLoginService(loginReq.getLoginType());
        //如果手机号码不为空，则加密
       loginReq.setPhone(encryptionUtils.encrypt(loginReq.getPhone()));
        LoginUser loginUser = loginService.login(loginReq);

        return RespResult.success(loginUser);
    }

}

